package com.example.radiobutton_checkbox;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

public class Checkbox extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    private CheckBox cb_one;
    private CheckBox cb_two;
    private CheckBox cb_three;
    private Button btn_send;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_checkbox);
        cb_one = (CheckBox) findViewById(R.id.cb_banana);
        cb_two = (CheckBox) findViewById(R.id.cb_apple);
        cb_three = (CheckBox) findViewById(R.id.cb_snowPear);
        btn_send = (Button) findViewById(R.id.btn_Submit);

        cb_one.setOnCheckedChangeListener(this);
        cb_two.setOnCheckedChangeListener(this);
        cb_three.setOnCheckedChangeListener(this);
        btn_send.setOnClickListener(this);




        int rb_paddingLeft = getResources().getDrawable(R.mipmap.ic_checkbox_checked).getIntrinsicWidth()+5;
        cb_one.setPadding(rb_paddingLeft, 0, 0, 0);
    }

    @Override
    public void onClick(View v) {
        String choose = "";
        if (cb_one.isChecked()) choose += cb_one.getText().toString() + "";
        if (cb_two.isChecked()) choose += cb_two.getText().toString() + "";
        if (cb_three.isChecked()) choose += cb_three.getText().toString() + "";
        Toast.makeText(this, choose, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView.isChecked())
            Toast.makeText(this, buttonView.getText().toString(), Toast.LENGTH_SHORT).show();
    }
}